package com.toymate.ai.asr;

import cn.hutool.extra.spring.SpringUtil;
import com.toymate.ai.asr.model.aliyun.AliyunSttService;
import com.toymate.ai.asr.model.baidu.BaiduSttService;
import com.toymate.common.constant.AiConstant;
import com.toymate.common.constant.ParamConstant;
import com.toymate.modules.iot.entity.IotRole;
import com.toymate.modules.iot.service.IotRoleService;

/**
 * STTFactory
 *
 * @author weirdor (179946422@qq.com)
 * @version v1.0.0
 */
public final class STTFactory {

    private static IotRoleService iotRoleService;

    static {
        STTFactory.iotRoleService = SpringUtil.getBean(IotRoleService.class);
    }

    public static AbstractSttService build(IotRole role) {
        //根据角色ID查询角色信息
        AsrConfig config = iotRoleService.getValueObject(role.getRoleId(), ParamConstant.ASR, AsrConfig.class);
        if (AiConstant.sttService.BAIDU.getValue().equals(config.getAsrType())) {
            return new BaiduSttService(config);
        }
        if (AiConstant.sttService.ALIYUN.getValue().equals(config.getAsrType())) {
            return new AliyunSttService(config);
        }
        return null;
    }
}
